package com.cuitrip.component.item;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.widget.TextView;

import com.cuitrip.service.R;

/**
 * Created by sheena on 16/2/2.
 */
public class CtTextView extends TextView{

    private int ctTextSizeStyle;
    private int ctTextColorStyle;
    private int ctBackgroundStyle;
    private Context mContext;

    public static final int SIZE_TITLE = 0;
    public static final int SIZE_NORMAL = 1;
    public static final int SIZE_OTHER = 2;

    public static final int COLOR_THEME_TRAVELER = 0;
    public static final int COLOR_THEME_INSIDER = 1;
    public static final int COLOR_TITLE = 2;
    public static final int COLOR_TEXT = 3;
    public static final int COLOR_WHITE = 4;


    public static final int BACKGROUND_ORANGE = 0;
    public static final int BACKGROUND_BLUE = 1;
    public static final int BACKGROUND_WHITE = 2;
    public static final int BACKGROUND_GREEN = 3;

    public CtTextView(Context context) {
        this(context, null);
    }

    public CtTextView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CtTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initInternal(context, attrs, defStyleAttr);
    }

    private void initInternal(Context context, AttributeSet attrs, int defStyleAttr) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CtTextView, defStyleAttr, R.style.CtTextView_Default);
        ctTextSizeStyle = a.getInt(R.styleable.CtTextView_ctTextSize, -1);
        ctTextColorStyle = a.getInt(R.styleable.CtTextView_ctTextColor, -1);
        ctBackgroundStyle = a.getInt(R.styleable.CtTextView_ctBackground, -1);
        a.recycle();
        mContext=context;
        bindViewData();
    }

    private void bindViewData() {
        setCtTextSizeStyle(ctTextSizeStyle);
        setCtTextColorStyle(ctTextColorStyle);
        setCtBackgroundStyle(ctBackgroundStyle);
    }

    private void setCtBackgroundStyle(int style) {
        switch (style){
            case BACKGROUND_ORANGE:
                setBackgroundResource(R.drawable.shape_orange_rec_corner);
                break;

            case BACKGROUND_BLUE:
                setBackgroundResource(R.drawable.shape_blue_rec_corner);
                break;

            case BACKGROUND_WHITE:
                setBackgroundResource(R.drawable.shape_white_corner_orange_line);
                break;

            case BACKGROUND_GREEN:
                setBackgroundResource(R.drawable.select_green_rec_corner);
                break;
        }
    }

    public void setCtTextSizeStyle(int style){
        switch (style){
            case SIZE_TITLE:
                setTextSize(TypedValue.COMPLEX_UNIT_DIP,19);
                break;

            case SIZE_NORMAL:
                setTextSize(TypedValue.COMPLEX_UNIT_DIP,17);
                break;

            case SIZE_OTHER:
                setTextSize(TypedValue.COMPLEX_UNIT_DIP,15);
                break;
        }
    }

    public void setCtTextColorStyle(int style){
        switch (style){
            case COLOR_THEME_TRAVELER:
                this.setTextColor(mContext.getResources().getColor(R.color.orange_ff6855));
                break;

            case COLOR_THEME_INSIDER:
                this.setTextColor(mContext.getResources().getColor(R.color.sky_blue_00d4ff));
                break;

            case COLOR_TITLE:
                this.setTextColor(mContext.getResources().getColor(R.color.ct_black));
                break;

            case COLOR_TEXT:
                this.setTextColor(mContext.getResources().getColor(R.color.qiaomai_7c706e));
                break;


            case COLOR_WHITE:
                this.setTextColor(mContext.getResources().getColor(R.color.ct_white));
                break;
        }
    }

}
